{"ast":null,"code":"import _slicedToArray from\"/Users/poppie/Desktop/development/messenger/app/frontend/node_modules/@babel/runtime/helpers/esm/slicedToArray.js\";import React from\"react\";import{generateAvatarByNickname}from\"../../utils/helpers\";import{Carousel}from\"../index\";import{observer}from\"mobx-react-lite\";import{Context}from\"../../index\";import{v4 as uuidv4}from\"uuid\";import'./Avatar.scss';import{jsx as _jsx}from\"react/jsx-runtime\";import{jsxs as _jsxs}from\"react/jsx-runtime\";var Avatar=function Avatar(_ref){var contentList=_ref.contentList,alt=_ref.alt,stringForGenerateColor=_ref.stringForGenerateColor,stringForFirstCharacter=_ref.stringForFirstCharacter,_ref$shortAvatar=_ref.shortAvatar,shortAvatar=_ref$shortAvatar===void 0?true:_ref$shortAvatar,_ref$selfProfile=_ref.selfProfile,selfProfile=_ref$selfProfile===void 0?false:_ref$selfProfile,chat=_ref.chat;var _React$useContext=React.useContext(Context),store=_React$useContext.store;var _React$useState=React.useState(null),_React$useState2=_slicedToArray(_React$useState,2),collection=_React$useState2[0],setCollection=_React$useState2[1];var _generateAvatarByNick=generateAvatarByNickname(stringForGenerateColor),colors=_generateAvatarByNick.colors;var firstChar=stringForFirstCharacter[0].toUpperCase();var changeHandler=React.useCallback(function(e){if(e.target.files&&e.target.files[0]){var file=e.target.files[0];e.target.value='';return store.uploadAvatar(file);}},[store]);var deleteHandler=React.useCallback(function(data,index){if(chat&&chat.id){return store.deleteChatAvatarFromAPI(data,index,chat);}else{return store.deleteUserAvatarFromAPI(data,index);}},[chat]);React.useEffect(function(){if(!shortAvatar&&contentList!==null&&contentList!==void 0&&contentList.items&&(contentList===null||contentList===void 0?void 0:contentList.items.length)>0){if(selfProfile){setCollection(contentList.items.map(function(item,index){return/*#__PURE__*/_jsxs(\"div\",{className:\"avatar__block-item\",children:[/*#__PURE__*/_jsx(\"img\",{className:\"avatar\",src:process.env.REACT_APP_BACKEND_URL+'/'+item.link,alt:'Avatar '+alt},index),/*#__PURE__*/_jsx(\"div\",{className:\"avatar__block-delete\",onClick:function onClick(){return deleteHandler(item,index);}},uuidv4())]},uuidv4());}));}else{setCollection(contentList.items.map(function(item,index){return/*#__PURE__*/_jsx(\"div\",{className:\"avatar__block-item\",children:/*#__PURE__*/_jsx(\"img\",{className:\"avatar\",src:process.env.REACT_APP_BACKEND_URL+'/'+item.link,alt:'Avatar '+alt},index)},uuidv4());}));}}},[contentList,alt,deleteHandler,selfProfile,shortAvatar]);if(shortAvatar){if(contentList&&contentList.items.length>0){return/*#__PURE__*/_jsx(\"img\",{className:\"avatar\",src:process.env.REACT_APP_BACKEND_URL+'/'+contentList.items[0].link,alt:'Avatar '+alt});}else{return/*#__PURE__*/_jsx(\"div\",{style:{background:\"linear-gradient(135deg, \".concat(colors.color,\" 0%, \").concat(colors.colorLighten,\" 96.52%)\")},className:\"avatar avatar--symbol\",children:firstChar});}}else{if(selfProfile){if(contentList!==null&&contentList!==void 0&&contentList.items&&contentList!==null&&contentList!==void 0&&contentList.items.length&&collection){return/*#__PURE__*/_jsxs(\"div\",{className:\"avatar__block\",children:[/*#__PURE__*/_jsx(Carousel,{width:210,children:collection}),contentList.items.length<5&&/*#__PURE__*/_jsx(\"div\",{className:\"avatar__uploader\",children:/*#__PURE__*/_jsx(\"input\",{type:\"file\",accept:\"image/*\",onChange:function onChange(e){return changeHandler(e);}})})]});}else{return/*#__PURE__*/_jsxs(\"div\",{className:\"avatar__block\",children:[/*#__PURE__*/_jsx(\"div\",{style:{background:\"linear-gradient(135deg, \".concat(colors.color,\" 0%, \").concat(colors.colorLighten,\" 96.52%)\")},className:\"avatar avatar--symbol\",children:firstChar}),/*#__PURE__*/_jsx(\"div\",{className:\"avatar__uploader\",children:/*#__PURE__*/_jsx(\"input\",{type:\"file\",accept:\"image/*\",onChange:function onChange(e){return changeHandler(e);}})})]});}}else{if(contentList&&collection){if(contentList.items.length===1){return/*#__PURE__*/_jsx(\"img\",{className:\"avatar\",src:process.env.REACT_APP_BACKEND_URL+'/'+contentList.items[0].link,alt:'Avatar '+alt});}else{return/*#__PURE__*/_jsx(Carousel,{width:210,children:collection});}}else{return/*#__PURE__*/_jsx(\"div\",{style:{background:\"linear-gradient(135deg, \".concat(colors.color,\" 0%, \").concat(colors.colorLighten,\" 96.52%)\")},className:\"avatar avatar--symbol\",children:firstChar});}}}};export default observer(Avatar);","map":{"version":3,"names":["React","generateAvatarByNickname","Carousel","observer","Context","v4","uuidv4","Avatar","contentList","alt","stringForGenerateColor","stringForFirstCharacter","shortAvatar","selfProfile","chat","useContext","store","useState","collection","setCollection","colors","firstChar","toUpperCase","changeHandler","useCallback","e","target","files","file","value","uploadAvatar","deleteHandler","data","index","id","deleteChatAvatarFromAPI","deleteUserAvatarFromAPI","useEffect","items","length","map","item","process","env","REACT_APP_BACKEND_URL","link","background","color","colorLighten"],"sources":["/Users/poppie/Desktop/development/messenger/app/frontend/src/components/Avatar/index.tsx"],"sourcesContent":["import React from \"react\";\nimport {AvatarProps} from \"../../models/props/AvatarProps\";\nimport { generateAvatarByNickname } from \"../../utils/helpers\";\nimport {Carousel} from \"../index\";\nimport {observer} from \"mobx-react-lite\";\nimport {Context} from \"../../index\";\nimport {ContentListItem} from \"../../models/response/ContentListItem\";\nimport {v4 as uuidv4} from \"uuid\";\nimport './Avatar.scss';\n\nconst Avatar: React.FC<AvatarProps> = ({\n       contentList,\n       alt,\n       stringForGenerateColor,\n       stringForFirstCharacter,\n       shortAvatar = true,\n       selfProfile = false,\n       chat,\n}) => {\n    const {store} = React.useContext(Context);\n    const [collection, setCollection] = React.useState<React.ReactNode | React.ReactNode[]>(null);\n\n    const {colors} = generateAvatarByNickname(stringForGenerateColor);\n    const firstChar = stringForFirstCharacter[0].toUpperCase();\n\n    const changeHandler = React.useCallback( (e: React.ChangeEvent<HTMLInputElement>) => {\n        if (e.target.files && e.target.files[0]) {\n            const file: File = e.target.files[0];\n            e.target.value = '';\n\n            return store.uploadAvatar(file);\n        }\n    }, [store]);\n\n    const deleteHandler = React.useCallback((data: ContentListItem, index: number) => {\n            if (chat && chat.id) {\n                return store.deleteChatAvatarFromAPI(data, index, chat);\n            } else {\n                return store.deleteUserAvatarFromAPI(data, index);\n            }\n    }, [chat]);\n\n    React.useEffect(() => {\n        if (!shortAvatar && contentList?.items && contentList?.items.length > 0) {\n            if (selfProfile) {\n                setCollection(\n                    contentList.items.map((item, index) => {\n                        return (\n                            <div\n                                className=\"avatar__block-item\"\n                                key={uuidv4()}\n                            >\n                                <img\n                                    key={index}\n                                    className='avatar'\n                                    src={process.env.REACT_APP_BACKEND_URL + '/' + item.link}\n                                    alt={'Avatar ' + alt}\n                                />\n                                <div\n                                    key={uuidv4()}\n                                    className=\"avatar__block-delete\"\n                                    onClick={() => deleteHandler(item, index)}\n                                />\n                            </div>\n                        );\n                    })\n                );\n            } else {\n                setCollection(\n                    contentList.items.map((item, index) => {\n                        return (\n                            <div\n                                className=\"avatar__block-item\"\n                                key={uuidv4()}\n                            >\n                                <img\n                                    key={index}\n                                    className='avatar'\n                                    src={process.env.REACT_APP_BACKEND_URL + '/' + item.link}\n                                    alt={'Avatar ' + alt}\n                                />\n                            </div>\n                        );\n                    })\n                );\n            }\n        }\n    }, [contentList, alt, deleteHandler, selfProfile, shortAvatar]);\n\n    if (shortAvatar) {\n        if (contentList && contentList.items.length > 0) {\n            return (\n                <img\n                    className='avatar'\n                    src={process.env.REACT_APP_BACKEND_URL + '/' + contentList.items[0].link}\n                    alt={'Avatar ' + alt}\n                />\n            );\n        } else {\n            return (\n                <div\n                    style={{background: `linear-gradient(135deg, ${colors.color} 0%, ${colors.colorLighten} 96.52%)`}}\n                    className='avatar avatar--symbol'\n                >\n                    {firstChar}\n                </div>\n            );\n        }\n    } else {\n        if (selfProfile) {\n            if (contentList?.items && contentList?.items.length && collection) {\n                return (\n                    <div className=\"avatar__block\">\n                        <Carousel width={210} >\n                            {collection}\n                        </Carousel>\n                        {(contentList.items.length < 5 &&\n                            <div className='avatar__uploader'>\n                                <input\n                                    type=\"file\"\n                                    accept=\"image/*\"\n                                    onChange={e => changeHandler(e)}\n                                />\n                            </div>\n                        )}\n                    </div>\n                );\n            } else {\n                return (\n                    <div className=\"avatar__block\">\n                        <div\n                            style={{background: `linear-gradient(135deg, ${colors.color} 0%, ${colors.colorLighten} 96.52%)`}}\n                            className='avatar avatar--symbol'>\n                            {firstChar}\n                        </div>\n                        <div className='avatar__uploader'>\n                            <input\n                                type=\"file\"\n                                accept=\"image/*\"\n                                onChange={e => changeHandler(e)}\n                            />\n                        </div>\n                    </div>\n                );\n            }\n        } else {\n            if (contentList && collection) {\n                if (contentList.items.length === 1) {\n                    return (\n                        <img\n                            className='avatar'\n                            src={process.env.REACT_APP_BACKEND_URL + '/' + contentList.items[0].link}\n                            alt={'Avatar ' + alt}\n                        />\n                    );\n                } else {\n                    return (\n                        <Carousel width={210} >\n                            {collection}\n                        </Carousel>\n                    );\n                }\n            } else {\n                return (\n                    <div\n                        style={{background: `linear-gradient(135deg, ${colors.color} 0%, ${colors.colorLighten} 96.52%)`}}\n                        className='avatar avatar--symbol'>\n                        {firstChar}\n                    </div>\n                );\n            }\n        }\n    }\n}\n\nexport default observer(Avatar);\n"],"mappings":"8IAAA,MAAOA,MAAK,KAAM,OAAO,CAEzB,OAASC,wBAAwB,KAAQ,qBAAqB,CAC9D,OAAQC,QAAQ,KAAO,UAAU,CACjC,OAAQC,QAAQ,KAAO,iBAAiB,CACxC,OAAQC,OAAO,KAAO,aAAa,CAEnC,OAAQC,EAAE,GAAIC,OAAM,KAAO,MAAM,CACjC,MAAO,eAAe,CAAC,wFAEvB,GAAMC,OAA6B,CAAG,QAAhCA,OAA6B,MAQ7B,IAPCC,YAAW,MAAXA,WAAW,CACXC,GAAG,MAAHA,GAAG,CACHC,sBAAsB,MAAtBA,sBAAsB,CACtBC,uBAAuB,MAAvBA,uBAAuB,uBACvBC,WAAW,CAAXA,WAAW,2BAAG,IAAI,wCAClBC,WAAW,CAAXA,WAAW,2BAAG,KAAK,kBACnBC,IAAI,MAAJA,IAAI,CAEP,sBA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